/*
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
 *
 * Copyright (c) 2013-2014 jfinal app. jfapp Group.
 */

define(['adminapp'], function ($app) {
    $app.navactive('game_game');
    var state_tpl = Handlebars.compile($(g.statetpl).html());
    var action_tpl = Handlebars.compile($(g.actiontpl).html());
    var picture_tpl = Handlebars.compile($(g.picturetpl).html());

    var $listtable = $app.listtable({
        'sAjaxSource' : g.ctx + "admin/game/game/list",
        'aoColumns'   : [
            $app.checkall,
            $app.autono,
            {'mDataProp': 'categoryName' },
            {'mDataProp': 'name' },
            {'mDataProp': 'picture' },
            {'mDataProp': 'state' }
        ],
        'aoColumnDefs': [
            {
                'aTargets': [4],
                'mData'   : null,
                'mRender' : function (data, type, full) {
                    return full['ruleWinning'] + "/" + full['ruleTotal'];
                }
            },
            {
                'aTargets': [5],
                'mData'   : null,
                'mRender' : function (data, type, full) {
                    var img = full.picture;
                    var thumbnail = img;
                    if (img) {
                        thumbnail = img.replace('.', '.thumbnail.');
                    }
                    var context = {'picture' : img, 'thumbnail' : thumbnail};
                    /*if (full.img) {
                     full.img = full.img.replace('.', '.thumbnail.')
                     }*/
                    //console.log(full.img);
                    return picture_tpl(context);
                }
            },
            {
                'aTargets': [6],
                'mData'   : null,
                'mRender' : function (data, type, full) {
                    return state_tpl(full);
                }
            },
            {
                'aTargets': [7],
                'mData'   : null,
                'mRender' : function (data, type, full) {
                    return action_tpl(full);
                }
            }
        ]
    }, 'data-list');

    $('#search_btn').on('click', function (e) {
        e.preventDefault();
        $listtable.fnReloadAjax();
    });
});

